package com.jiezheng.huinong.action;

import java.util.ArrayList;
import java.util.List;

import com.jiezheng.huinong.dao.UserManageDAOImpl;
import com.jiezheng.huinong.model.UserInfo;
import com.jiezheng.huinong.util.JqPage;
import com.opensymphony.xwork2.ActionSupport;

public class UserInfoAction extends ActionSupport {
	
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 5003621224019043210L;
	
	private JqPage pageInfo = new JqPage();
	private List<UserInfo> users = new ArrayList<UserInfo>();
	private String sord = "";
	private String sidx = "";
	
	/**
	 * 列出所有用户
	 * @return
	 */
	public String listUserInfo(){
		
		Integer total =  (new UserManageDAOImpl()).getTotalUserNum();
		Integer totalPage = (Integer)(total / pageInfo.getRows()) + ((total % pageInfo.getRows() == 0) ? 0 : 1) ; 
		pageInfo.setTotalPage(totalPage);
		pageInfo.setRecord(total);
		//取得当前页
		Integer curPage = pageInfo.getPage();
		Integer startRow = (curPage - 1) * pageInfo.getRows(); 
		
		users = (new UserManageDAOImpl()).getUserInfo(startRow, pageInfo.getRows());
		return SUCCESS;
	}
	
	
	public JqPage getPageInfo() {
		return pageInfo;
	}

	public void setPageInfo(JqPage pageInfo) {
		this.pageInfo = pageInfo;
	}

	public List<UserInfo> getUsers() {
		return users;
	}

	public void setUsers(List<UserInfo> users) {
		this.users = users;
	}

	public String getSord() {
		return sord;
	}

	public void setSord(String sord) {
		this.sord = sord;
	}

	public String getSidx() {
		return sidx;
	}

	public void setSidx(String sidx) {
		this.sidx = sidx;
	}

}
